﻿using System.Collections.Generic;
using System.Linq;
using HappyBa.Core.Interfaces;

namespace HappyBa.Core.Validators
{
    public class EachUserStoryShouldHaveBaValidator : IValidator
    {
        public IEnumerable<ValidationResult> Validate(ValidationContext context)
        {
            foreach (var entity in context.Metrics.UserStories)
            {
                if (!entity.Assignments.Any(x => string.Equals(x.Role.Name, Constants.BARole)))
                {
                    yield return new ValidationResult(
                        string.Format("{0}: {1} should have assigned BA", entity.EntityType.Name, entity.Id))
                    {
                        Entity = entity
                    };
                }
            }
        }
    }
}
